#include<iostream>
using namespace std;
const int N =1e5+10;
int a[N],b[N];
int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++) cin>>a[i];
  int length=0;
  for(int l=0,r=0;r<n;r++){
    b[a[r]]++;
    while (b[a[r]]>1){
      b[a[l]]--;
      l++;
    }
    length=max(length,r-l+1);
  }
  cout<<length;
}